package cn.lyjuan.payment.third.http.api.vo.req;

import cn.lyjuan.payment.third.base.common.enums.impl.ChlEnum;
import cn.lyjuan.payment.third.base.pay.chl.impl.ali.bean.AlipayTransferReq;
import cn.lyjuan.payment.third.base.pay.chl.impl.ali.enums.AliServiceEnum;
import cn.lyjuan.payment.third.base.pay.chl.impl.weixin.bean.WxTransferReq;
import cn.lyjuan.payment.third.base.pay.chl.impl.weixin.enums.WxTradeType;
import cn.lyjuan.payment.third.base.pay.vo.req.TransferReq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@ApiModel("转账订单数据")
public class TransferReqVo {
    @ApiModelProperty(value = "应用ID", required = true)
    @NotNull
    private Integer appId;

    @ApiModelProperty(value = "支付渠道", required = true)
    @NotNull
    private ChlEnum chlType;

    @ApiModelProperty(value = "交易流水号", required = true)
    @NotNull
    private String appNo;

    @ApiModelProperty(value = "标题", required = true)
    @NotNull
    private String title;

    @ApiModelProperty(value = "身份", required = true)
    @NotNull
    private String identity;

    @ApiModelProperty(value = "备注", required = false)
    private String remark;

    @ApiModelProperty(value = "平台额外参数", required = false)
    private TransferParams params;

    @ApiModelProperty(value = "应自定义参数", notes = "在通知和回调时原样返回")
    private String flag;

    @ApiModelProperty(value = "金额", notes = "单位：分", required = true)
    @Min(1)
    @Max(999999)
    private Integer amt;

    @ApiModelProperty("MD5 32位签名")
    private String sign;

    @ApiModel("平台额外参数")
    public static class TransferParams {

        @ApiModelProperty(value = "支付调用方式", notes = "支付宝")
        private AliServiceEnum service;

        @ApiModelProperty(value = "微信交易类型", notes = "微信")
        protected WxTradeType tradeType;

        @ApiModelProperty(value = "真实姓名", notes = "校验用户姓名选项时,必填")
        private String realName;

        @ApiModelProperty(value = "随机字符串", notes = "微信")
        protected String noncestr;

        @ApiModelProperty(value = "校验用户姓名选项", notes = "默认false (当identity不是支付宝用户id时, 必 true)")
        protected boolean checkName = false;

        @ApiModelProperty(value = "ip", notes = "微信")
        protected String ip;

        @ApiModelProperty(value = "设备号", notes = "微信")
        protected String deviceInfo;

        /**
         * 获取参数
         *
         * @return ITransferReq
         */
        public TransferReq.ITransferReq params(ChlEnum chlType) {
            switch (chlType) {
                case ALI:
                    return ali();
                case WX_MP:// 微信公众号与开放平台参数相同
                case WX_OPEN:
                    return wechat();
                case IAP:
                    return null;
            }
            return null;
        }

        private AlipayTransferReq ali() {
            return new AlipayTransferReq(service, realName, checkName);
        }

        private WxTransferReq wechat() {
            return new WxTransferReq(tradeType, noncestr, checkName, deviceInfo, realName, ip);
        }

        public String getRealName() {
            return realName;
        }

        public void setRealName(String realName) {
            this.realName = realName;
        }

        public AliServiceEnum getService() {
            return service;
        }

        public void setService(AliServiceEnum service) {
            this.service = service;
        }

        public WxTradeType getTradeType() {
            return tradeType;
        }

        public void setTradeType(WxTradeType tradeType) {
            this.tradeType = tradeType;
        }

        public String getNoncestr() {
            return noncestr;
        }

        public void setNoncestr(String noncestr) {
            this.noncestr = noncestr;
        }

        public boolean isCheckName() {
            return checkName;
        }

        public void setCheckName(boolean checkName) {
            this.checkName = checkName;
        }
    }

    public Integer getAppId() {
        return appId;
    }

    public void setAppId(Integer appId) {
        this.appId = appId;
    }

    public ChlEnum getChlType() {
        return chlType;
    }

    public void setChlType(ChlEnum chlType) {
        this.chlType = chlType;
    }

    public String getAppNo() {
        return appNo;
    }

    public void setAppNo(String appNo) {
        this.appNo = appNo;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public Integer getAmt() {
        return amt;
    }

    public void setAmt(Integer amt) {
        this.amt = amt;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public TransferParams getParams() {
        return params;
    }

    public void setParams(TransferParams params) {
        this.params = params;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public String toString() {
        return "OrderReq{" +
                "appId=" + appId +
                ", chlType=" + chlType +
                ", appNo='" + appNo + '\'' +
                ", goods='" + title + '\'' +
                ", flag='" + flag + '\'' +
                ", amt=" + amt +
                ", sign='" + sign + '\'' +
                '}';
    }
}
